//
//  LYRecommendClassViewController.m
//  artist
//
//  Created by Jay_Apple on 16/5/11.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYRecommendClassViewController.h"
#import "LYEArtistCell.h"
#import "LYCollectListModel.h"
#import "LYClassWebViewController.h"

@interface LYRecommendClassViewController ()

@property (nonatomic, strong) NSArray *models;

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation LYRecommendClassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"推荐课程";
    
    [self loadClassData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 网络请求

- (void)loadClassData{
    
    [MBProgressHUD showMessage:nil];
    
    [LYRequestTool commandSubjectListWithToken:LYToken success:^(NSArray<LYMyClassListModel *> *models) {
        [MBProgressHUD hideHUD];
        self.models = models;
        [self.tableView reloadData];
        
    } failure:^(NSString *code, NSString *message) {
        [MBProgressHUD hideHUD];
    }];

}


#pragma mark - tableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 80;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LYMyClassListModel *model = self.models[indexPath.row];
    LYClassWebViewController *classWebVC = [LYClassWebViewController classWebVCWithID:model.Id];
    [self.navigationController pushViewController:classWebVC animated:YES];
    
}

#pragma mark - tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.models.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"LYEArtistCell";
    LYEArtistCell *cell = [LYEArtistCell cellWithTableView:tableView andIndetifier:cellID];
    
    //model
    LYMyClassListModel *model = self.models[indexPath.row];
    cell.model = model;
    
    return cell;
    
}


@end
